//
//  AfterSaleServiceViewController.swift
//  OnceNectar
//
//  Created by apple on 2018/3/6.
//  Copyright © 2018年 com.inwhoop. All rights reserved.
//

import UIKit

class AfterSaleServiceViewController: BaseViewController, UITableViewDelegate, UITableViewDataSource ,AfterSaleServiceTableViewCellDelegate{
    
    @IBOutlet var tableView: UITableView!
    
    var model:myOrderModel?
    var seletedIndex: NSInteger = -1
    
    override func viewDidLoad() {
        super.viewDidLoad()
        initUI()
        
    }

    override func setNavigation() {
        
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        
    }
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return (self.model?.purchaseGoodsInfos?.count)!
    }
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! AfterSaleServiceTableViewCell
        cell.delegate = self
        cell.setData(model: (self.model?.purchaseGoodsInfos![indexPath.row])!)
        return cell
    }
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return 155
    }
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        seletedIndex = indexPath.row
        tableView.reloadData()
    }
    
}
extension AfterSaleServiceViewController {
    func initUI() {
        
        tableView.register(UINib(nibName: "AfterSaleServiceTableViewCell", bundle: nil), forCellReuseIdentifier: "cell")
        tableView.tableHeaderView = setHeaderView()
    }
    
    
    
    func setHeaderView() -> UIView {
        titleLabel(text: "售后服务", nil)
        
        let headerView = UIView()
        headerView.backgroundColor = UIColor(hex: 0xb2b2b2)
        headerView.frame = CGRect(x: 0, y: 0, width: tableView.width, height: 60)
        
        let afView = AfterSaleHeadView.loadFromNib()
        afView.frame = CGRect(x: 0, y: 10, width: tableView.width, height: 50)
        headerView.addSubview(afView)
        
        return headerView
    }
    
    func req(cell:AfterSaleServiceTableViewCell) {
        let indexPath = self.tableView.indexPath(for: cell)
        let vc = ReleaseAfterSaleViewController(nibName: "\(ReleaseAfterSaleViewController.self)", bundle: nil)
        vc.model = self.model
        vc.pgiId = self.model?.pgiIds?.components(separatedBy: ",")[(indexPath?.row)!]
        self.navigationController?.pushViewController(vc, animated: true);
    }

}

